/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#ifndef INCLUDE_SHADER_COLOR
#define INCLUDE_SHADER_COLOR

#include "shader_built_in_functions.h"
#include "shader_binding_ID.h"


#ifdef __cplusplus

#include "basic_def.h"
#include "basic_vec.h"

// GLSL Type
using uint = unsigned int;

#define in
#define out
#define inout



static vec2 cw_V0 = vec2{ 0.0f, 1 };
static vec2 cw_V1 = vec2{ 0.86603f, -0.5f };
static vec2 cw_V2 = vec2{ -0.86603f, -0.5f };

/*Inline vec3 mix(const vec3& v1, const vec3& v2, float32 a) {
	vec3 outVal;
	outVal.x = v1.x * (1 - a) + v2.x * a;
	outVal.y = v1.y * (1 - a) + v2.y * a;
	outVal.z = v1.z * (1 - a) + v2.z * a;
	return outVal;
}*/


#else

vec2 cw_V0 = vec2(0.0, 1);
vec2 cw_V1 = vec2(0.86603, -0.5);
vec2 cw_V2 = vec2(-0.86603, -0.5);

#define Inline


#endif



#include "texture.h"





struct S_ColorTake {
	vec3 color;
	vec2 coord;
	//����
	float intensity;
};

struct S_ColorGradient {
	float take_r;
	float take_g;
	float take_b;
	float take_a;
	uint controlPointNum;
	uint dir;
};

struct S_LineProp {
	float	m_Gap;
	uint	m_ColorA;
	uint	m_ColorB;
};


Inline vec4 f_glsl_buildColor(in uint color) {
	vec4 TColor;
	TColor.x = float((color & 0xff000000) >> 24) / 255.0;
	TColor.y = float((color & 0x00ff0000) >> 16) / 255.0;
	TColor.z = float((color & 0x0000ff00) >> 8) / 255.0;
	TColor.w = float((color & 0x000000ff)) / 255.0;
	return TColor;
};

Inline vec3 f_glsl_RGB_to_HSV(in vec3 rgb) {
	vec3 HSV;
	float ma = max(max(rgb.x, rgb.y), rgb.z);
	float mi = min(min(rgb.x, rgb.y), rgb.z) + 0.0000001;

	HSV.z = ma;
	HSV.y = (ma - mi) / ma;

	if (rgb.x == ma) HSV.x = (rgb.y - rgb.z) / (ma - mi) * 60.0f;
	if (rgb.y == ma) HSV.x = (rgb.z - rgb.x) / (ma - mi) * 60.0f + 120;
	if (rgb.z == ma) HSV.x = (rgb.x - rgb.y) / (ma - mi) * 60.0f + 240;

	if(HSV.x < 0) HSV.x += 360.0f;

	return HSV;
}




#undef in
#undef out

#endif